
import {
	getStorageWidthSex
} from '@/common/request/storageSyncData.js'

export default {

	menuItemClick(index,item) {


		for (var i = 0; i < this.menuListDatas.length; i++) {

			var menuItem = this.menuListDatas[i];
			if (i == index) {
				menuItem.sqlState = true;
			} else {
				menuItem.sqlState = false
			}

		}
		this.rankCode = item.rankCode;
		this.$refs.paging.reload()
		
		


	},
	async queryList(pageNo, pageSize) {
		var _this = this;
		
		console.log(pageNo,pageSize);
		
		if(_this.menuListDatas.length <1){
			await _this.getRankInfoListData();
		}
		
		if(_this.menuListDatas.length <1){
			_this.$refs.paging.complete([])
		}else{
			this.getRankItemDetailData();
		}
		
		
		
		
	},
	enterBookInfoDetail(e){
		var bookInfoStr = JSON.stringify(e);
		uni.navigateTo({
			url: '/pages/baseBusiness/bookInfoDetail/bookInfoDetailView?bookInfo='+bookInfoStr
		})
	},
	async getRankInfoListData(){
		
		var that = this;
		var dataInfo = getStorageWidthSex().id;
		var param = {
			rankGender:dataInfo
		}

	   var res = await that.$api.getRankInfoList(param);
	   console.log(res,"-------asdasd-sss")
	   if(res.data.code == 200){
	   	that.menuListDatas = res.data.rows
	   	that.menuListDatas.forEach((item,index) => {
	   	 if(index == 0){
	   		 item.sqlState = true;
	   		 that.rankCode = item.rankCode;
	   	 }else{
	   		 item.sqlState = false;
	   	 }
	   	})
		return
	   }else{
	   	return
	   }
		
		
		
		
	},
	async getRankItemDetailData(){
		var that = this;
		var localHttp = that.$http_url.getHttpUrl();
		var dataRes = await this.$sqlDBConfig.selectCollectionTableData2();
		that.$api.getRankItemDetail(that.rankCode).then(res => {
			if(res.data.code == 200){
				var bookList = res.data.rows;
				bookList.forEach(function(item, index) {
				      item.bookIconUrl = localHttp+"/images/"+item.bookCode+"/"+item.bookPic;
					  item.isCollection = false
					  dataRes.forEach(function(item1, index1) {
							  if(item1.bookcode == item.bookCode){
								   item.isCollection = true
							  }
					  })
				})
				that.$refs.paging.complete(bookList)
				
			}else{
				
			}
		}).catch(error => {
			
		})
	}

}
